import { Component } from '@angular/core'
import { IonicPage, NavController, NavParams } from 'ionic-angular'
import { Camera, CameraOptions } from '@ionic-native/camera'
import { ImagePicker, ImagePickerOptions } from '@ionic-native/image-picker'
import {
  FileTransfer,
  FileUploadOptions,
  FileTransferObject
} from '@ionic-native/file-transfer'
import { File } from '@ionic-native/file'
import { Base64 } from '@ionic-native/base64'
// import {
//   MediaCapture,
//   MediaFile,
//   CaptureError,
//   CaptureImageOptions,
//   CaptureVideoOptions
// } from '@ionic-native/media-capture'

/**
 * Generated class for the MeseaminspectionworkdetailitemsPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-meseaminspectionworkdetailitems',
  templateUrl: 'meseaminspectionworkdetailitems.html'
})
export class MeseaminspectionworkdetailitemsPage {
  data: any[]
  imgPath: any = [
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541062311515&di=9ab03d891c33447fc6e2123aba953b56&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F8b95155f4090543e17ba34c79ee41303b7d08b003c216-Afxfed_fw658',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541062311515&di=e27d3b1871c6a2329a54580c5b5383b4&imgtype=0&src=http%3A%2F%2Fimgsa.baidu.com%2Fexp%2Fw%3D500%2Fsign%3Ddce3e99f9f13b07ebdbd50083cd69113%2F77c6a7efce1b9d16daebf4dfffdeb48f8c54645b.jpg',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541062311515&di=8eaaa04a5273d84a998833fd32f76385&imgtype=0&src=http%3A%2F%2Fimg.25pp.com%2Fuploadfile%2Fapp%2Fcapture%2Fiphone6p%2F20180104%2F1515053671169444.jpg',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541062311515&di=9ab03d891c33447fc6e2123aba953b56&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F8b95155f4090543e17ba34c79ee41303b7d08b003c216-Afxfed_fw658',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541062311515&di=9ab03d891c33447fc6e2123aba953b56&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F8b95155f4090543e17ba34c79ee41303b7d08b003c216-Afxfed_fw658',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541062311515&di=9ab03d891c33447fc6e2123aba953b56&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F8b95155f4090543e17ba34c79ee41303b7d08b003c216-Afxfed_fw658'
  ]
  gender: string
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private camera: Camera,
    private transfer: FileTransfer,
    private file: File,
    private imagePicker: ImagePicker,
    private base64: Base64 // public mediaCapture: MediaCapture
  ) {}

  ionViewDidLoad() {
    this.data = this.navParams.get('x')
  }
  inspection() {}
  openCamera(name) {
    const options: CameraOptions = {
      quality: 90, //相片质量 0 -100
      destinationType: this.camera.DestinationType.DATA_URL, //DATA_URL 是 base64   FILE_URI 是文件路径
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      saveToPhotoAlbum: true, //是否保存到相册
      sourceType: this.camera.PictureSourceType[name]
      //是打开相机拍照还是打开相册选择  PHOTOLIBRARY : 相册选择, CAMERA : 拍照,
    }

    this.camera.getPicture(options).then(
      imageData => {
        console.log('got file: ' + imageData)

        // If it's base64:
        let base64Image = 'data:image/jpeg;base64,' + imageData
        this.imgPath.unshift(base64Image)

        //If it's file URI
        // this.path = imageData;

        // this.upload();
      },
      err => {
        // Handle error
      }
    )
  }
  openVideo() {
    // let options: CaptureVideoOptions = { limit: 1, duration: 10 } //limit 一次只拍摄一个视频，duration:视频的拍摄最长时间
    // this.mediaCapture.captureVideo(options).then(
    //   (data: MediaFile[]) => {
    //     //拍摄成功后返回的实体 数组
    //     console.log(data)
    //     // Promise.reject('success to save the db')
    //     let path: string = data[0].fullPath.toString() // MediaFile.fullPath 表示视频的绝对路径
    //   },
    //   (err: CaptureError) => {
    //     console.error(err)
    //   }
    // )
  }
  delImg(index) {
    this.imgPath.splice(index, 1)
  }
  imgClick(x) {}
}
